package net.xinqushi.socket.bio;

import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.net.InetAddress;
import java.net.Socket;

/**
 * @author xjie 2019/7/12 16:13
 * @description
 */
public class Client {

    public static void main(String[] args) {
        //bind port and address
        try {
            //Socket client = new Socket("localhost", 80);
            //with a local address
            InetAddress localAddress = InetAddress.getLocalHost();
            Socket client = new Socket("localhost", 80 );
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
            bw.write("something i want to say you !! ");
            bw.close();//autoFlush when wrapperStream close and socket closed , stream end

            //when wrapperStream close ,socket is close ? Whether or not?
            // the result socket is closed when socketInputStream closed
            // @see SocketOutputStream#close
            System.out.println(client);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
